// forcetalk.txt
// Liek alknpc, but this character will aprroach and speak with character first time.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1 - Number of state when talked to. Plays default text if 0.
//   Cell 2,3 -  Stuff done flag. if it is 0, this character hunts party down
//   Cell 4 - Speaking range. Range pc is within to hunt down. Default to 12.
begincreaturescript;

variables;

short i,target;
short has_greeted = 0;
short speak_range = 12;
short which_exit = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Levi");
	set_level(ME,10);
	set_boss_level(ME,2);
	set_attack_bonus(ME,10);
	set_new_abil(ME,20);
	
	if (gf(66,6) > 0)
		erase_char(ME);
	
	if (get_memory_cell(4) > 0)
		speak_range = get_memory_cell(4);
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE;
	if (gf(66,1) == 0)
		end();
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		set_state(3);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
		
	if ((get_attitude(ME) < 10) && (get_ran(1,0,100) < 30))
		give_char_text_bubble(ME,"Turn back!");

	if (gf(66,6) == 0) {
		approach_char(ME,pc_num(),1);
		set_state(4);
		}
	if (gf(66,6) > 0) {
		approach_nav_point(ME,which_exit,1);
		if (dist_to_nav_point(ME,which_exit) <= 2)
			erase_char(ME);
		}



break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate 4; // approaching pc
	if ((get_attitude(ME) < 10) && (get_ran(1,0,100) < 30))
		give_char_text_bubble(ME,"Turn back!");

	if (get_flag(66,6) > 0)
		set_state(START_STATE);
	if (get_attitude(ME) >= 10) {
		set_state(START_STATE);
		}
	if ((approach_char(ME,pc_num(),1)) || (dist_to_pc() <= 4)) {
		if (dist_to_nav_point(ME,1) < dist_to_nav_point(ME,which_exit))
			which_exit = 1;
		if (dist_to_nav_point(ME,2) < dist_to_nav_point(ME,which_exit))
			which_exit = 2;
		if (dist_to_nav_point(ME,3) < dist_to_nav_point(ME,which_exit))
			which_exit = 3;
		set_flag(66,6,1);
		talk_no_exit(35);
		}
break;


beginstate TALKING_STATE;
		print_str("Talking: Levi is too eager to get away to talk much.");

break;